/**
 * @param {number[]} nums
 * @param {number} val
 * @return {number}
 */
var removeElement = function(nums, val) {
    var count = 0, i=0, length = nums.length;

    for(i=0;i<length;i++){
        if(nums[i]===val){
            count++;
            var temp = nums[i];
            nums[i] = nums[nums.length-count];
            nums[nums.length-count] = temp;
            length--;
            i--;
        }
    }
    var res = nums.splice(nums.length-count,count);
    return nums;//res.length;
};

var nums = [2];
var res = removeElement(nums,3);
console.log(res,nums);